package com.qishenyuan.competition.vo;

import com.qishenyuan.competition.constant.UserConstant;
import com.qishenyuan.competition.model.FindJob;
import com.qishenyuan.competition.model.User;
import com.qishenyuan.competition.utils.AliOssUtil;
import com.qishenyuan.competition.utils.DateUtil;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * @author Jacky
 * @since 2025-03-25
 */
@Data
public class FindJobBriefResp {

    private Integer id;

    private String title;

    private String userName;

    private String avatar;

    private String school;

    private String major;

    private String createTime;

    private Integer tag;

    private Integer type;

    public static FindJobBriefResp buildVo(FindJob findJob, User user){
        FindJobBriefResp resp = new FindJobBriefResp();
        resp.setId(findJob.getId());
        resp.setTitle(findJob.getTitle());
        resp.setMajor(findJob.getMajor());
        resp.setCreateTime(DateUtil.format(findJob.getCreateTime(), DateUtil.FORMAT_YYYY_MM_DD));
        resp.setTag(findJob.getTag());
        resp.setType(findJob.getType());
        if (!Objects.isNull(user)) {
            if (!StringUtils.isBlank(user.getNickName())) {
                resp.setUserName(user.getNickName());
            }
            if (UserConstant.DEFAULT_AVATAR.equals(user.getAvatar())) {
                resp.setAvatar(UserConstant.DEFAULT_AVATAR);
            }else {
                resp.setAvatar(AliOssUtil.generatePreSignedUrl(user.getAvatar()));
            }
            resp.setSchool(user.getSchool());
        }
        return resp;
    }
}
